/******
 *  understand c++ CLASS
 * A SIMPLE CLASS AND ITS USING SYNTAX
 * 
 ****/

#include <iostream>
using namespace std;
struct Boxer
{
    string name;
    int weight;
    unsigned short life;
    Boxer(string pname, int pweight)
    {
        name = pname;
        weight = pweight;
        life = 100;
    }
    void introduce()
    {
        cout << "HI! I am " << name << " and I am " << weight << "kg!" << endl;
    }
    void show()
    {
        cout << name << ":" << life << "%" << endl;
    }
    unsigned short punch()
    {
        unsigned short t = rand() % 2;
        cout << name << " punch " << (t == 0 ? "left" : "right") << endl;
        return t;
    }
    unsigned short dodge()
    {
        unsigned short t = rand() % 2;
        cout << name << " dodge " << (t == 0 ? "left" : "right") << endl;
        return t;
    }
    void loseBlood()
    {
        life -= 10;
        if (life == 0)
            cout << name << " is dead!" << endl;
    }
    bool ifLive()
    {
        return life > 0;
    }
    void bite(Boxer &b)     //compare Boxer b Boxer * b
    {
        cout << name << " bite " << b.name << endl;
        life += 10;
        b.life -= 10;
    }

};
int main()
{
    Boxer b1 = Boxer("Tyson", 80);
    b1.introduce();
    Boxer b2("Ali", 80); // Boxer b2 = Boxer("Ali", 80);
    b2.introduce();
    b1.show();
    b2.show();
    srand(time(NULL));
    cout << b1.name << " FIGHT! "<<b2.name << endl;
    while (b1.ifLive() && b2.ifLive())
    {
        cout<<string(5,'*')<<endl;
        if (b1.punch() == b2.dodge())
            b2.loseBlood();
        if (b2.punch() == b1.dodge())
            b1.loseBlood();
        b1.show();
        b2.show();
    }
}